/***************************************************************************
 *   Copyleft 2008-2009 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>									   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#include "./vGlSoftwareVertexBuffer.h"
#include "../../Exceptions/vFatalException.h"
#include "GL/glew.h"
#include "../../Macros/vGlMacros.h"

namespace Vendetta {
	vGlSoftwareVertexBuffer::vGlSoftwareVertexBuffer(vUInt uiSize, vUInt32 ui32Format, 
		vVertexBuffer::eVertexBufferPrimitiveType ePrimitiveType, vVertexBuffer::eVertexBufferUsage eUsage) 
			:vVertexBuffer(uiSize, ui32Format, ePrimitiveType, eUsage), mBufferID(0) {
		switch(ePrimitiveType) {
			case VVBPT_QUADS:
				mPrimitiveType = GL_QUADS;
				break;
			case VVBPT_TRIANGLES:
			default:
				mPrimitiveType = GL_TRIANGLES;
				break;
			case VVBPT_TRIANGLE_STRIP:
				mPrimitiveType = GL_TRIANGLE_STRIP;
				break;
		}
	}


	vGlSoftwareVertexBuffer::~vGlSoftwareVertexBuffer()	{
		if (mUsage == VVBU_STATIC) {

		}
	}

	vVoid vGlSoftwareVertexBuffer::Use() {
		glBegin(mPrimitiveType);
		for (vUInt i = 0; i < mVertexCount; i++) {
			if (mFormat & VVBF_UV) {
				glTexCoord2fv(mpTexCoords[i].Values);
			}
			if (mFormat & VVBF_RGBA) {
				glColor4fv(mpColors[i].Values);
			}
			if (mFormat & VVBF_NXNYNZ) {
				glNormal3fv(mpNormals[i].Values);
			}
			glVertex3fv(mpVertices[i].Values);
		}
		glEnd(); V_GL_ASSERT
	}

	vBool vGlSoftwareVertexBuffer::build() {
		if (mUsage == VVBU_DYNAMIC) {
			return true;
		}

		return false;
	}

	/************************************************************************/
	/* Disabled                                                             */
	/************************************************************************/
	vGlSoftwareVertexBuffer::vGlSoftwareVertexBuffer() { 
		V_CHECK_MSG(0, "Some tries to call default vGlSoftwareVertexBuffer ctor."); 
	}

	vGlSoftwareVertexBuffer::vGlSoftwareVertexBuffer(const vGlSoftwareVertexBuffer& oGlVertexBuffer) { 
		V_CHECK_MSG(0, "Some tries to call vGlSoftwareVertexBuffer copy ctor."); 
	}

	vGlSoftwareVertexBuffer& vGlSoftwareVertexBuffer::operator=(const vGlSoftwareVertexBuffer& oGlVertexBuffer) { 
		V_CHECK_MSG(0, "Some tries to call vGlSoftwareVertexBuffer operator=."); 

		return *this; 
	}
	/************************************************************************/
}